import Vue from 'vue'
import Router from 'vue-router'
import login from '@/views/login'
import studentMain from '@/views/studentMain'
import studentcourse from '@/views/studentcourse'
import studentInfo from '@/views/studentInfo'
import test from '@/views/test'
import ElementUI from "element-ui";
import { Message } from 'element-ui';
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: login,
      meta: {
        keepAlive: false,
      }
    },

    {
      path: '/studentMain',
      name: 'studentMain',
      component: studentMain,
      meta: {
        keepAlive: true,
      },
      children: [
        {
          path: '/studentcourse',
          name: 'studentcourse',
          component: studentcourse,
          meta: {
            keepAlive: true,
          },
        },
        
      ]
    },
    {
      path: '/studentInfo',
      name: 'studentInfo',
      component: studentInfo,
      meta: {
        keepAlive: true
      },
    },
    {
      path: '/test',
      name: 'test',
      component: test
    }
  ]
})
router.beforeEach((to, from, next) => {
  let isLogin = sessionStorage.getItem("user");
  if (to.path == '/') return next();
  if (!isLogin) {
    Message.warning("请先登入")
    return next('/')
  }

  // if(to.path=='/loginout'){
  //   storage.clear();
  //   //设置cookie过期
  //   document.cookie = "isLogin" + "=;expires=" + new Date(0).toGMTString();
  //   console.log(new Date(0).toGMTString());
  //   next('/login');
  // }

  // if(document.cookie.indexOf('isLogin')==-1){
  //   storage.clear();
  //   if(to.path!="/login"&&to.path!="/scanfqr"){
  //     next({
  //       path:'/login'
  //     })
  //   }
  // }
  next()

})
export default router;